//
//  BTEListInputTableViewCell.swift
//  BTE
//
//  Created by Mike Zhang on 2025/9/2.
//

import UIKit

class BTEListInputTableViewCell: UITableViewCell,UITextFieldDelegate {

    let box1 = UIView()
    let b1 = UILabel()
    let t1text = UITextField()
    
    var model: BTECarnepalaeoglacioewelogyNetModel?
    
    var callBack:(()->())?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        
        box1.backgroundColor = .white
        box1.roundCorners(.allCorners, radius: 12)
        box1.layer.borderWidth = 3
        box1.layer.borderColor = UIColor.colorWithHex("#082252")!.cgColor
        contentView.addSubview(box1)
        box1.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(15)
            make.top.bottom.equalToSuperview().inset(12)
        }
        
        box1.addSubview(b1)
        b1.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(14)
            make.left.equalToSuperview().offset(16)
        }
        
        t1text.font = .systemFont(ofSize: 14,weight: .bold)
        t1text.textColor = .black
        box1.addSubview(t1text)
        t1text.snp.makeConstraints { make in
            make.left.equalTo(b1)
            make.right.equalToSuperview().offset(-12)
            make.height.equalTo(44)
            make.bottom.equalToSuperview()
            make.top.equalTo(b1.snp.bottom).offset(10)
        }
        
        t1text.delegate = self
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
           let currentText = textField.text ?? ""
           let newText = (currentText as NSString).replacingCharacters(in: range, with: string)
        model?.tripylaean = newText
        callBack?()
           return true
    }
    
}
